﻿@using DevExpress.Blazor
@using DevExpress.Blazor.Internal;
@using DevExpress.ExpressApp.Blazor;
@using DevExpress.ExpressApp.Blazor.Components
@using Microsoft.AspNetCore.Components.Web

<div>
    <DxTabs class="xaf-mdi" ActiveTabIndex="@CurrentWindowIndex" ActiveTabIndexChanged="@WindowTemplate.OnActiveTabIndexChanged" RenderMode="TabsRenderMode.OnDemand">
        @foreach (var window in CurrentWindowGroup.Windows)
        {
            <DxTab>
                <TabTemplate>
                    <div class="tab-item dxbl-text" @oncontextmenu="e=>ShowMdiContextMenuAsync(window,e)" @oncontextmenu:preventDefault>
                        <span>
                            @DxImage.IconCssOrImage(null, ImageUrlService.GetImageUrl(window.GetImageName()), "tab-item-image")
                        </span>
                        <span>
                            @window.GetCaption()
                        </span>
                        @if (window.Template is IMdiFrameTemplate t && t.HasUnsavedChanges)
                        {
                            <span>*</span>
                        }
                        <span class="@TabPageCloseClass" @onclick:stopPropagation="true">
                            <XafImage ImageName="Delete" Size="12" @onclick="e => WindowTemplate.CloseWindowAsync(window)" />
                        </span>
                    </div>
                </TabTemplate>
            </DxTab>
        }
    </DxTabs>

    <DxContextMenu @ref="MdiContextMenu">
        <Items>
            <DxContextMenuItem Text="移动到新窗口" Enabled="@IsMoveToNewWindowEnabled" Click="async ()=> await MoveTabToNewWindow()" />
            <DxContextMenuItem Text="关闭标签" Enabled="@IsCloseTabEnabled" BeginGroup="true" Click="async ()=> await CloseTabAsync()" />
            <DxContextMenuItem Text="关闭左侧标签" Enabled="@IsCloseLeftTabsEnabled" BeginGroup="true" Click="async ()=> await CloseLeftTabsAsync()" />
            <DxContextMenuItem Text="关闭右侧标签" Enabled="@IsCloseRightTabsEnabled" Click="async ()=> await CloseRightTabsAsync()" />
            <DxContextMenuItem Text="关闭其它标签" Enabled="@IsCloseOtherTabsEnabled" BeginGroup="true" Click="async ()=> await CloseOtherTabsAsync()" />
            <DxContextMenuItem Text="关闭全部标签" Enabled="@IsCloseAllTabsEnabled" Click="async ()=> await CloseAllTabsAsync()" />
        </Items>
    </DxContextMenu>
</div>
